package service;

import java.util.HashMap;
import java.util.Map;

import persistence.dao.DaoManager;
import service.impl.CityServiceImpl;
import service.impl.OrderServiceImpl;
import service.impl.RoutsServiceImpl;
import service.impl.RoutsStantionServiceImpl;
import service.impl.UsersServiceImpl;

public class ServiceManager {
	@SuppressWarnings("rawtypes")
	private Map<Class, Object> serviceObjects;
	private DaoManager daoManager;
	
	private ServiceManager() {
		super();
		this.init();
	}
	
	protected DaoManager getDaoManager() {
		return daoManager;
	}

	public static ServiceManager getDefault() {
		return new ServiceManager();
	}

	@SuppressWarnings("rawtypes")
	private void init() {
		daoManager = DaoManager.getDefault();
		serviceObjects = new HashMap<Class, Object>();
		
		serviceObjects.put(CityService.class, new CityServiceImpl(getDaoManager()));
		serviceObjects.put(RoutsService.class, new RoutsServiceImpl(getDaoManager()));
		serviceObjects.put(OrderService.class, new OrderServiceImpl(getDaoManager()));
		serviceObjects.put(UsersService.class, new UsersServiceImpl(getDaoManager()));
		serviceObjects.put(RoutsStantionService.class, new RoutsStantionServiceImpl(getDaoManager()));
	}
	
	public RoutsService getRoutsService() {
		return (RoutsService) serviceObjects.get(RoutsService.class);
	}
	
	public CityService getCityService() {
		return (CityService) serviceObjects.get(CityService.class);
	}
	
	public OrderService getOrderService() {
		return (OrderService) serviceObjects.get(OrderService.class);
	}
	
	public UsersService getUsersService() {
		return (UsersService) serviceObjects.get(UsersService.class);
	}
	
	public RoutsStantionService getRoutsStantionService() {
		return (RoutsStantionService) serviceObjects.get(RoutsStantionService.class);
	}
	
}
